/* nmanga (nichiManga) - manga downloader for Readmanga.me/MintManga.com
 *
 *
 * */
#include <stdio.h>
#include <stdlib.h>

#include "getimglinks.h"
#include "options.h"
#include "printing.h"
#include "utils.h"

int
main(int argc, char** argv)
{
	/* iteration valriables declaration */
	int i;

	/* normal variables declaration */
	struct input_data *id;
	struct imglinks *ils;
	struct options *opts;

	opts = emalloc(sizeof(struct options));
	opts = scan_options(argc, argv, opts);

	if (opts->be_verbose) {
		print_info(opts);
	}

	if (opts->read_from_stdin) {
		id = read_stdin();
		if (opts->reader_name == UNDEFINED) {
			printf("FATAL ERROR: reader is not entered. Abort.\n");
			exit(EXIT_FAILURE);
		}else if (opts->reader_name == READMANGA) {
			ils = getimglinks_readmanga(id);
		} else if (opts->reader_name == MINTMANGA) {
			ils = getimglinks_mintmanga(id);
		}
	}

	if (opts->read_from_stdin){
			for(i=0; i < ils->num; i++) {
				printf("%s\n", ils->lst[i]->link);
		}
	}

	return 0;
}
